<template>
    <div>
      <TopNav></TopNav>
      <div class="news">
        <div class="title">{{ name }}</div>
        <div class="time">{{ newsCreatedAt }}</div>
        <div class="content">
          <div v-html="content" class="text"></div>
          <p class="link">
            转载自：
            <a :href="url" target="_blank">{{ source }}</a>
          </p>
        </div>
      </div>
    </div>
  </template>
      
  <script>
  import TopNav from '~/components/h5/topNav'
  export default {
    layout:'mobile',
    name: "siteNav",
    head() {
      return {
        title: this.name || "新闻",
      };
    },
    props: {
      componentContent: {
        type: Object,
      },
    },
    components: {TopNav},
    computed: {},
    async asyncData({ $indexApi, params }) {
      const id = params.id;
      const res = await $indexApi.getNewsById({
        id: id,
      });
      if (res.code == "0") {
        return {
          //评论列表
          name: res.data.name,
          content: res.data.content,
          url: res.data.url,
          source: res.data.source,
          newsCreatedAt: res.data.newsCreatedAt,
        };
      }
    },
    data() {
      return {
        id: "",
        name: "",
        content: "",
        url: "",
        source: "",
        newsCreatedAt: "",
      };
    },
    mounted() {
      window.scrollTo(0, 0);
      // this.id = this.$route.query.id;
      // this.getNewsById();
    },
    methods: {
      async getNewsById() {
        const res = await this.$indexApi.getNewsById({
          id: this.id,
        });
        if (res.code == 0) {
          this.name = res.data.name;
          this.content = res.data.content;
          // this.content=JSON.parse(this.content)
          this.url = res.data.url;
          this.source = res.data.source;
          this.newsCreatedAt = res.data.newsCreatedAt;
        }
      }
    },
  };
  </script>
      
      <style lang="scss" scoped>
  .news {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    width: 95%;
    margin: 0 auto;
    padding-top: 30px;
    .title {
      font-size: 24px;
      font-weight: 700;
      letter-spacing: 6px;
      line-height: 40px;
      color: rgba(13, 21, 46, 0.65);
      width: 970px;
      text-align: center;
    }
    .time {
      width: 100%;
      text-align: center;
      margin-top: 10px;
      font-size: 14px;
      font-weight: 400;
      line-height: 30px;
      color: rgba(13, 21, 46, 0.65);
    }
    .content {
      font-size: 16px;
      font-weight: 400;
      letter-spacing: 0px;
      line-height: 20px;
      color: rgba(13, 21, 46, 0.65);
      width: 100%;
    }
    .link {
      text-align: end;
      a {
        // text-decoration: none;
        color: #999;
      }
    }
  }
  ::v-deep img {
    max-width: 90% !important;
  }
  </style>
      